package com.cd.cms.common.utils;


import java.text.SimpleDateFormat;

public class Header {
	/**
	 * 请求
	 */
	public final static int REQUEST = 0;
	/**
	 * 应答
	 */
	public final static int RESPONSE = 1;
	
	/**
	 * 游客
	 */
	public final static String GUEST = "guest";
	
	/**
	 * 功能号，必填
	 */
	private String action;
	/**
	 * 区分请求/应答类型，必填
	 */
	private Integer msgtype;
	/**
	 * 用户ID，必填
	 */
	private String userid;
	/**
	 * 设备类型，必填
	 */
	private String devicetype;
	/**
	 * sessionid号，登录成功后服务端返回
	 */
	private String sessionid;
	/**
	 * 请求者IP或者MAC地址，预留
	 */
	private String ip;
	/**
	 * 发送时间，格式：yyyy-MM-dd HH:mm:ss
	 */
	private String sendingtime;
	/**
	 * 签名方式，预留
	 */
	private String signmode;
	/**
	 * 签名信息，预留
	 */
	private String signmsg;
	/**
	 * 版本号
	 */
	private String version;
	/**
	 * 错误号，0：成功，非0：失败
	 */
	private String code;
	/**
	 * 错误信息
	 */
	private String msg;
	
	/**
	 * 日期格式："yyyy-MM-dd HH:mm:ss"
	 * 
	 * @return
	 */
	public static String getDateTime() {
		SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		return tempDate.format(new java.util.Date());
	}
	
	public Header() {
		this.code = "0";
		this.sendingtime = getDateTime();
		this.version = "1.0.01";
	}
	
	public Header(Header header) {
		this();
		create(header);
	}
	
	public void create(Header header) {
		if (header != null) {
			this.action = header.action;
			this.userid = header.userid;
			this.sessionid = header.sessionid;
		}
	}
	
	public void init(Header header) {
		if (header != null) {
			this.userid = header.userid;
			this.devicetype = header.devicetype;
			this.sessionid = header.sessionid;
		}
	}

	public String getAction() {
		return action;
	}


	public void setAction(String action) {
		this.action = action;
	}

	public Integer getMsgtype() {
		return msgtype;
	}

	public void setMsgtype(Integer msgtype) {
		this.msgtype = msgtype;
	}

	public String getUserid() {
		return userid;
	}


	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getDevicetype() {
		return devicetype;
	}


	public void setDevicetype(String devicetype) {
		this.devicetype = devicetype;
	}

	public String getSessionid() {
		return sessionid;
	}

	public void setSessionid(String sessionid) {
		this.sessionid = sessionid;
	}

	public String getIp() {
		return ip;
	}


	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getSendingtime() {
		return sendingtime;
	}

	public void setSendingtime(String sendingtime) {
		this.sendingtime = sendingtime;
	}

	public String getSignmode() {
		return signmode;
	}


	public void setSignmode(String signmode) {
		this.signmode = signmode;
	}


	public String getSignmsg() {
		return signmsg;
	}


	public void setSignmsg(String signmsg) {
		this.signmsg = signmsg;
	}


	public String getVersion() {
		return version;
	}


	public void setVersion(String version) {
		this.version = version;
	}


	public String getCode() {
		return code;
	}


	public void setCode(String code) {
		this.code = code;
	}


	public String getMsg() {
		return msg;
	}


	public void setMsg(String msg) {
		this.msg = msg;
	}
}
